package com.sos.flex.ui.validators
{
	import com.sos.Application;
	
	import mx.validators.StringValidator;
	import mx.validators.ValidationResult;
	
	public class DeckNameValidator extends StringValidator
	{
		public function DeckNameValidator()
		{
			super();
		}
		
		
		override protected function doValidation(value:Object):Array 
		{
			// Ancestor validation
			var results:Array =  super.doValidation(value);
			// Return if there are errors.
			if (results.length > 0) return results;
			
			// Verify that the name is unique in the collection
			
			if (Application.instance.collection.containsDeckByName(value.toString()))
			{
				results.push(new ValidationResult(true, "", "", "Name already used for another deck in the collection!"));
			}
			
			return results;
		}
		
	}
}